<template>
    <div class="addlist">
 <van-nav-bar
  title="地址列表"
  left-text="返回"
  right-text="编辑地址"
  left-arrow
  @click-left="onClickLeft"
  @click-right="onClickRight"
/>
<van-address-list
  v-model="chosenAddressId"
  :list="list"
  disabled-text="以下地址超出配送范围"
  default-tag-text="默认"
  @add="onAdd"
  @edit="onEdit"
/>
    </div>
</template>
<script>
import { getaddresses } from "@/api/address";
import { Toast } from "vant";
export default{
  data() {
    return {
    chosenAddressId: '1',
      list: [],
    }
   
  },
   methods: {
    async addresslist(){
      let result = await getaddresses();
      let obj = {};
      let newList = [];
      result.addresses.forEach((item)=>{
        obj = {
          ...item,
          name:item.receiver,
          tel:item.mobile,
          address:item.regions,
          isDefault:item.isDefault,
        };
        newList.push(obj);
      });
      this.list=newList.splice(4,4);
    },
    onClickLeft(){
      this.$router.go(-1);
    },
    onClickRight(){},
         onAdd() {
      this.$router.push("address")
    },
    onEdit(item, index) {
      Toast('编辑地址:' + index);
    },
    },
     created() {
    this.addresslist();
  },
}
</script>